#!/bin/bash
security unlock-keychain -p 111111
flutter clean
flutter build ipa --release --export-options-plist=./ExportOptions.plist
# 将登录钥匙串设置为默认，避免设备出现认证问题：
# keychain use-login

outputPath="build/ios/ipa"
filePath="build/ios/ipa/pax_info_app.ipa"
echo "正在上传至蒲公英平台"
#蒲公英的ukey apikey
curl -F "file=@${filePath}" -F "uKey=faf0a1136a9170211bc1d768c6f4e621" -F "_api_key=897df95bc6c86875f5889843b35ed236" https://www.pgyer.com/apiv1/app/upload > $outputPath/code.text

result=`cat ${outputPath}/code.text`

result1=`echo "${result##*"appQRCodeURL"}"`

length=`expr ${#result1} - 6`

result2=`echo ${result1:3:$length}`

result3=`echo $result2 | sed 's:\\\/:\/:g'`

if [ ! $result3 ];
then
   echo "~~~~~~~~~~~~~~~~~~~上传失败~~~~~~~~~~~~~~~~~~~"
else
   echo "~~~~~~~~~~~~~~~~~~~上传成功~~~~~~~~~~~~~~~~~~~"
   echo "生成的二维码链接为:${result3}"
fi

echo -e "\033[32m ✓ Build Success \033[0m";
echo -e "\033[32m ✓ File path：${filePath} \033[0m";
